$(function () {

    var transferHistory_datagrid = $("#transferHistory_datagrid")
    var transferHistory_datagrid_search_dialog = $("#transferHistory_datagrid_search_dialog");
    var transferHistory_datagrid_search_dialog_form = $("#transferHistory_datagrid_search_dialog_form");


    var cmdObj = {
        // 刷新历史
        reloadHistory: function () {
            transferHistory_datagrid.datagrid('reload');
        },
        // 高级查询
        advancedSearchHistory: function () {
            transferHistory_datagrid_search_dialog_form.form('clear');
            transferHistory_datagrid_search_dialog.dialog('open');
        },
        // 高级查询确认
        search_commit: function () {
            var clientName = $("#clientName").val();
            var formerlyId = $("#formerlyId").val();
            var nowId = $("#nowId").val();


            transferHistory_datagrid.datagrid('load', {
                'clientName': clientName,
                'formerlyId': formerlyId,
                'nowId': nowId
            });
        },
        // 高级查询取消
        search_cancel: function () {
            transferHistory_datagrid_search_dialog.dialog('close');
        }
    }

    // 统一方法调用
    $("a[data-cmd]").click(function () {
        cmdObj[$(this).data('cmd')]();
    });

    transferHistory_datagrid.datagrid({
        url: '/transferHistory/query',
        fit: true,
        fitColumns: true,
        striped: true,
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        width: 1000,
        columns: [[
            {field: 'id', title: '编号', halign: 'center', align: 'center', width: 100, hidden: true},
            {field: 'client', title: '客户名', halign: 'center', align: 'center', width: 100, formatter: formatClient},
            {field: 'qq', title: 'qq', halign: 'center', align: 'center', width: 100},
            {field: 'tel', title: '电话', halign: 'center', align: 'center', width: 100},
            {field: 'transferTime', title: '移交时间', halign: 'center', align: 'center', width: 100},
            {field: 'formerly', title: '移交人', halign: 'center', align: 'center', width: 100, formatter: formatFormerly},
            {field: 'now', title: '接手人', halign: 'center', align: 'center', width: 100, formatter: formatNow}
        ]],
        toolbar: '#transferHistory_datagrid_toolbar'
    });
});

function formatClient(value, row, index) {
    return value == null ? '' : value.name;
}
function formatFormerly(value, row, index) {
    return value == null ? '' : value.username;
}
function formatNow(value, row, index) {
    return value == null ? '' : value.username;
}
























